'use strict';

describe('Controller: MainCtrl', function () {

  // load the controller's module
    beforeEach(module('homepageApp'));

    var MainCtrl;
    var scope;
    var MainCtrl;
    var scope;
    var apiService;
    var q;
    var deferred;
    var imagesIGotBack;

    beforeEach(function() {
        imagesIGotBack = {"image_file_name":{"S":"images\/AWS_Logo_PoweredBy_300px.jpg"},"page_id":{"N":"1"}};
        apiService = {
            getImagesForPage:function (){
                deferred = q.defer();
                return deferred.promise;
            },
            getPostsForPage:function (){
                deferred = q.defer();
                return deferred.promise;
            }
        };
    });

    // Initialize the controller and a mock scope
    beforeEach(inject(function ($controller, $rootScope, $q) {
        q = $q;
        scope = $rootScope.$new();
        MainCtrl = $controller('MainCtrl', {
        $scope: scope,
        Backendservice: apiService
        });
    }));

    it('should request images for homepage', function(){
        spyOn(apiService, 'getImagesForPage').andCallThrough();

        scope.init();

        expect(apiService.getImagesForPage).toHaveBeenCalled();
    });

    it('should request posts for homepage', function(){
        spyOn(apiService, 'getPostsForPage').andCallThrough();

        scope.init();

        expect(apiService.getPostsForPage).toHaveBeenCalled();
    });

    it('should not get undefined result for images for homepage', function(){
        spyOn(apiService, 'getImagesForPage').andCallThrough();

        scope.init();

        expect(scope.images).not.toBe(undefined);
    });

    it('should not get null result for images for homepage', function(){
        spyOn(apiService, 'getImagesForPage').andCallThrough();

        scope.init();

        expect(scope.images).not.toBeNull;
    });
/*
    it('should get images for homepage', function(){
        scope.init();

        deferred.resolve(imagesIGotBack);
        scope.$root.$digest();

        expect(scope.images.image_file_name.S).toBe("images\/AWS_Logo_PoweredBy_300px.jpg");
    });
*/
});
